package com.harmontronics.hanma.paas.paas.domain.app.entity.valueobject;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;

/**
 * 视图支持的数据库
 */
public enum ViewDataBaseTypeEnum {


    POSTGRES("postgresql", "org.postgresql.Driver"),
    MYSQL("mysql", "com.mysql.cj.jdbc.Driver"),
    ORACLE("oracle","oracle.jdbc.OracleDriver"),
    MSSQL("sqlserver","com.microsoft.sqlserver.jdbc.SQLServerDriver");

    private String code;
    private String driver;


    private boolean clazzLoaded = false;

    ViewDataBaseTypeEnum(String code, String driver) {
        this.code = code;
        this.driver = driver;
    }


    public void loadDriver() throws ClassNotFoundException {
        if(clazzLoaded){
            return;
        }

            Class.forName(driver);
            clazzLoaded = true;

    }

    ViewDataBaseTypeEnum(String code) {
        this.code = code;
    }

    public static ViewDataBaseTypeEnum of(String code) {
        ViewDataBaseTypeEnum result = null;
        for (ViewDataBaseTypeEnum dataBaseTypeEnum : ViewDataBaseTypeEnum.values()) {
            if (dataBaseTypeEnum.getCode().equalsIgnoreCase(code)) {
                result = dataBaseTypeEnum;
                break;
            }
        }
        return result;
    }


    public String getCode() {
        return code;
    }

    public String getDriver() {
        return driver;
    }
}
